home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
L' Effet Pommier 2
/
L'Effet Pommier - Volume 02.iso
/
Arcade
/
Marathon Bonus
/
WAD exporters
/
dmsnd.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-13
|
3KB
|
158 lines
#include <Sound.h>
#include <stdio.h>
#include <string.h>
#include <stddef.h>
#define SHORT(x) ((long)(x)[0]|(long)(x)[1]<<8)
typedef struct {
unsigned char three[2];
unsigned char rate[2];
unsigned char len[2];
unsigned char zero[2];
} sndhed;
#if GENERATINGPOWERPC
#pragma options align=mac68k
#endif
typedef struct {
short format;
short numModifiers;
ModRef modifierPart;
short numCommands;
SndCommand commandPart;
SoundHeader head;
} sss;
#if GENERATINGPOWERPC
#pragma options align=reset
#endif
static char wadname[]="doom.wad";
static char inname[]="doom sounds.exp";
static unsigned char outname[]="\pdoom sounds.rsrc";
void main(void)
{
char sname[8];
long soff,slen;
sndhed sh;
FILE *wad,*in;
FInfo fi;
short resref;
OSErr err;
long samples;
Fixed rate;
short sndid;
sss *sndptr;
Handle sndhand;
long len;
wad=fopen(wadname,"rb");
if (!wad) {
perror(wadname);
return;
}
in=fopen(inname,"r");
if (!in) {
perror(inname);
return;
}
CreateResFile(outname);
err=ResError();
if (err!=noErr) {
fprintf(stderr,"CreateResFile: %d\n",err);
return;
}
err=GetFInfo(outname,0,&fi);
if (err!=noErr) {
fprintf(stderr,"GetFInfo: %d\n",err);
return;
}
fi.fdType='rsrc';
fi.fdCreator='RSED';
err=SetFInfo(outname,0,&fi);
if (err!=noErr) {
fprintf(stderr,"SetFInfo: %d\n",err);
return;
}
resref=OpenResFile(outname);
if (resref==-1) {
err=ResError();
fprintf(stderr,"OpenResFile: %d\n",err);
return;
}
for (sndid=8192; ; sndid++) {
if (fscanf(in," DS%s %ld %ld",sname+1,&soff,&slen)!=3)
break;
printf("%s %ld %ld\n",sname+1,soff,slen);
if (slen<=sizeof (sndhed)) {
fprintf(stderr,"%s: Resource too short\n",sname+1);
continue;
}
if (fseek(wad,soff,SEEK_SET)) {
perror(sname+1);
continue;
}
if (fread(&sh,sizeof sh,1,wad)!=1) {
fprintf(stderr,"%s: Unexpected EOF\n",sname+1);
continue;
}
if (SHORT(sh.three)!=3 || SHORT(sh.zero)!=0) {
fprintf(stderr,"%s: Not a sound resource\n",sname+1);
continue;
}
samples=SHORT(sh.len);
rate=SHORT(sh.rate)<<16;
if (samples+sizeof sh>slen) {
fprintf(stderr,"%s: Invalid sound header\n",sname+1);
continue;
}
sndhand=NewHandle(offsetof(sss,head.sampleArea)+samples);
if (!sndhand) {
err=MemError();
fprintf(stderr,"%s: NewHandle: %d\n",sname+1,err);
continue;
}
HLockHi(sndhand);
sndptr=*(sss **)sndhand;
sndptr->format=1;
sndptr->numModifiers=1;
sndptr->modifierPart.modNumber=sampledSynth;
sndptr->modifierPart.modInit=initMono;
sndptr->numCommands=1;
sndptr->commandPart.cmd=bufferCmd|dataOffsetFlag;
sndptr->commandPart.param1=0;
sndptr->commandPart.param2=offsetof(sss,head);
sndptr->head.samplePtr=NULL;
sndptr->head.length=samples;
sndptr->head.sampleRate=rate;
sndptr->head.loopStart=0;
sndptr->head.loopEnd=0;
sndptr->head.encode=stdSH;
sndptr->head.baseFrequency=kMiddleC;
len=fread(sndptr->head.sampleArea,1,samples,wad);
if (len<samples) {
fprintf(stderr,"%s: Unexpected EOF\n",sname+1);
DisposeHandle(sndhand);
continue;
}
HUnlock(sndhand);
sname[0]=strlen(sname+1);
AddResource(sndhand,'snd ',sndid,(StringPtr)sname);
err=ResError();
if (err!=noErr) {
fprintf(stderr,"%s: AddResource: %d\n",sname+1,err);
DisposeHandle(sndhand);
continue;
}
WriteResource(sndhand);
ReleaseResource(sndhand);
}
CloseResFile(resref);
fclose(wad);
fclose(in);
return;
}